# coding=utf-8
# @Time   : 2023/11/26
# @Author : wangjl
# @Email  : 1975039138@qq.com
from typing import Dict, List


class JobParams(object):
    def __init__(self, args: List[str], name_arg_sep: str = ":"):
        self.args = args
        self.conf: Dict[str, str] = {}
        self.remain_args: List[str] = []

        for arg in self.args:
            if arg.startswith("-D"):
                key, value = arg.lstrip("-D").split("=", 1)
                self.conf[key] = value
            elif len(kv := arg.split(name_arg_sep, 1)) == 2:
                self.conf[kv[0]] = kv[1]
            else:
                self.remain_args.append(arg)

    @classmethod
    def from_sys_args(cls, args: List[str], sep: str = ":"):
        return cls(args[1:], sep)

    def get(self, key: str, default_value: str = None):
        return self.conf.get(key, default_value)

    @property
    def named_params(self) -> Dict[str, str]:
        return self.conf
